var express = require('express')
var router = express.Router()
const { getALL, getOne, exec } = require('../db')

// 解构调试的的标记,将来会根据这个决定是否发送错误信息
const { debug } = require('../config/index')

// 获取所有用户  方式一
router.get('/all', async (req, res, next) => {
  let sql = 'select * from user '
  const data = await getALL(sql)
  res.send({
    code: 0,
    message: '获取所有用户成功',
    result: data,
  })
})

// 获取所有用户  方式二
router.get('/all', async (req, res, next) => {
  let sql = 'select * from user '
  try {
    const data = await getALL(sql)
    res.send({
      code: 0,
      message: '获取所有用户成功',
      result: data,
    })
  } catch (error) {
    res.send({
      code: 1,
      message: '获取所有用户失败',
      result: debug ? error : '',
    })
  }
})

module.exports = router
